[XEN] Shadow: be more explicit in assuming that d->vcpu[0] is valid
authorTim Deegan <Tim.Deegan@xensource.com>
Fri, 9 Mar 2007 12:10:29 +0000 (12:10 +0000)
committerTim Deegan <Tim.Deegan@xensource.com>
Fri, 9 Mar 2007 12:10:29 +0000 (12:10 +0000)
Signed-off-by: Tim Deegan <Tim.Deegan@xensourc.com>
xen/arch/x86/mm/shadow/common.c
xen/include/asm-x86/paging.h

index 92bcc001ab2e0a71295792ab4e89ddb6915e8690..c8829abc2a4ca8b965907e7f415f05d2b6e4b452 100644 (file)
@@ -802,7 +802,7 @@ void shadow_prealloc(struct domain *d, unsigned int order)
     v = current;
     if ( v->domain != d )
         v = d->vcpu[0];
-    ASSERT(v != NULL);
+    ASSERT(v != NULL); /* Shouldn't have enabled shadows if we've no vcpus  */
 
     /* Stage one: walk the list of pinned pages, unpinning them */
     perfc_incrc(shadow_prealloc_1);
@@ -861,7 +861,9 @@ static void shadow_blow_tables(struct domain *d)
     struct vcpu *v = d->vcpu[0];
     mfn_t smfn;
     int i;
-    
+
+    ASSERT(v != NULL);
+
     /* Pass one: unpin all pinned pages */
     list_for_each_backwards_safe(l,t, &d->arch.paging.shadow.pinned_shadows)
     {
@@ -2384,6 +2386,7 @@ int shadow_enable(struct domain *d, u32 mode)
 
     /* Sanity check the arguments */
     if ( (d == current->domain) ||
+         d->vcpu[0] == NULL ||
          shadow_mode_enabled(d) ||
          ((mode & PG_translate) && !(mode & PG_refcounts)) ||
          ((mode & PG_external) && !(mode & PG_translate)) )
@@ -2993,6 +2996,13 @@ int shadow_domctl(struct domain *d,
         return 0;
     }
 
+    if ( unlikely(d->vcpu[0] == NULL) )
+    {
+        SHADOW_ERROR("Shadow op on a domain (%u) with no vcpus\n",
+                     d->domain_id);
+        return -EINVAL;
+    }
+
     switch ( sc->op )
     {
     case XEN_DOMCTL_SHADOW_OP_OFF:
index 249e206a5a8a05438502c97f9cf33d2a310572ab..0a3b01ce850ef392516bfd1943c2c005f2cbc1a2 100644 (file)
@@ -273,7 +273,7 @@ static inline void paging_write_p2m_entry(struct domain *d, unsigned long gfn,
     struct vcpu *v = current;
     if ( v->domain != d )
         v = d->vcpu[0];
-    if ( likely(paging_mode_enabled(d) && v->arch.paging.mode != NULL) )
+    if ( likely(v && paging_mode_enabled(d) && v->arch.paging.mode != NULL) )
     {
         return v->arch.paging.mode->write_p2m_entry(v, gfn, p, new, level);
     }